//
//  HBlackListCell.m
//  BXlive
//
//  Created by huangzhiwen on 2017/3/27.
//  Copyright © 2017年 cat. All rights reserved.
//

#import "HBlackListCell.h"
#import <Masonry/Masonry.h>
#import <SLDeveloperTools/SLDeveloperTools.h>
#import "GradientButton.h"
@interface HBlackListCell()
@property (nonatomic , strong) UIImageView *headImageView;//头像
@property (strong, nonatomic) UIImageView *realNameIV;
@property (nonatomic , strong) UILabel * nickNameLabel;//昵称
@property (strong, nonatomic) UIImageView *sexIV;
@property (strong, nonatomic) UIImageView *levelIV;
@property (strong, nonatomic) UIImageView *vipIV;
@property (nonatomic , strong) UILabel * signatureLabel;//个性签名
@property (nonatomic , strong) UIButton *removeBtn;//移除黑名单按钮
@end
@implementation HBlackListCell

+ (instancetype)cellWithTabelView:(UITableView *)tableView{
    
    HBlackListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HBlackListCell"];
    
    if (cell == nil) {
        cell = [[HBlackListCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"HBlackListCell"];
    }
    
    return cell;
}

- (instancetype) initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        [self setupUI];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return self;
}


- (void)setupUI{
    _headImageView = [[UIImageView alloc]initWithFrame:CGRectZero];
    _headImageView.layer.masksToBounds = YES;
    _headImageView.layer.cornerRadius = __ScaleWidth(24);
    [self.contentView addSubview:_headImageView];
    [_headImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.mas_equalTo(__ScaleWidth(48));
        make.left.mas_equalTo(__ScaleWidth(12));
        make.centerY.mas_equalTo(0);
    }];
    
    _realNameIV = [[UIImageView alloc]init];
    _realNameIV.image = [UIImage imageNamed:@"mine_app_Ident"];
    [self.contentView addSubview:_realNameIV];
    [_realNameIV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.mas_equalTo(13);
        make.right.bottom.mas_equalTo(self.headImageView).offset(-1);
    }];
    _realNameIV.hidden = YES;
    _removeBtn = [[GradientButton alloc] initWithFrame:CGRectZero];
    [_removeBtn setTitle:NSLocalizedString(@"移除黑名单", nil) forState:UIControlStateNormal];
    _removeBtn.titleLabel.font = SLPFFont(14);
//    _removeBtn.backgroundColor = sl_normalColors;
    _removeBtn.titleLabel.textAlignment = NSTextAlignmentCenter;
    [_removeBtn setTitleColor:sl_whiteTextColors forState:UIControlStateNormal];
    [_removeBtn.layer setMasksToBounds:YES];
    [_removeBtn.layer setCornerRadius:__ScaleWidth(15)];
//    [_removeBtn.layer setBorderWidth:1.0];
//    _removeBtn.layer.borderColor = normalColors.CGColor;
    [_removeBtn addTarget:self action:@selector(removeAction) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:_removeBtn];
    [_removeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(__ScaleWidth(86));
        make.height.mas_equalTo(__ScaleWidth(30));
        make.centerY.mas_equalTo(0);
        make.right.mas_equalTo(-15);
    }];
    
    _nickNameLabel = [[UILabel alloc]initWithFrame:CGRectZero];
    _nickNameLabel.textColor = sl_textColors;
    _nickNameLabel.font = SLBFont(16);
    _nickNameLabel.textAlignment = NSTextAlignmentLeft;
    [self.contentView addSubview:_nickNameLabel];
    [_nickNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.headImageView.mas_right).offset(__ScaleWidth(15));
        make.top.mas_equalTo(self.headImageView.mas_top).offset(__ScaleWidth(4));
        make.height.mas_equalTo(14);
        make.width.mas_greaterThanOrEqualTo(100);
    }];
    
    _signatureLabel = [[UILabel alloc]initWithFrame:CGRectZero];
    _signatureLabel.textColor = sl_textSubColors;
    _signatureLabel.textAlignment = NSTextAlignmentLeft;
    _signatureLabel.font = SLPFFont(12);
    [self.contentView addSubview:_signatureLabel];
    [_signatureLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.nickNameLabel);
        make.top.mas_equalTo(self.nickNameLabel.mas_bottom).offset(__ScaleWidth(9));
        make.height.mas_equalTo(__ScaleWidth(17));
        make.right.mas_equalTo(self.removeBtn.mas_left).offset(-5);
    }];
    
    
    _sexIV = [[UIImageView alloc]init];
    _sexIV.contentMode = UIViewContentModeScaleAspectFit;
    [self.contentView addSubview:_sexIV];
    [_sexIV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.mas_equalTo(15);
        make.left.mas_equalTo(self.nickNameLabel.mas_right).offset(__ScaleWidth(10));
        make.centerY.mas_equalTo(self.nickNameLabel);
    }];
    
    _levelIV = [UIImageView new];
    [self.contentView addSubview:_levelIV];
    [_levelIV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(30);
        make.height.mas_equalTo(14);
        make.left.mas_equalTo(self.sexIV.mas_right).offset(5);
        make.centerY.mas_equalTo(self.nickNameLabel);
    }];
    
    _vipIV = [[UIImageView alloc]initWithFrame:CGRectZero];
    _vipIV.image = [UIImage imageNamed:@"mine_vipIdentification"];
    [self.contentView addSubview:_vipIV];
    [_vipIV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.mas_equalTo(15);
        make.left.mas_equalTo(self.levelIV.mas_right).offset(5);
        make.centerY.mas_equalTo(self.nickNameLabel);
    }];
}

-(void)setModel:(HBlackListModel *)model{
    _nickNameLabel.text = model.nickname;
    CGFloat nickW = [UILabel getWidthWithTitle:model.nickname font:SLBFont(16)];
    [_nickNameLabel mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(nickW);
    }];
    _signatureLabel.text = model.sign;
    [_headImageView zzl_setImageWithURLString:[NSURL URLWithString:model.avatar] placeholder:nil];
    _levelIV.image = [UIImage imageNamed:[NSString stringWithFormat:@"level_%@",model.level]];
    [_sexIV mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(15);
    }];
    switch ([model.gender integerValue]) {
        case 0:
//            _sexIV.image = [UIImage imageNamed:@"gender_icon_weishezhi"];
            [_sexIV mas_updateConstraints:^(MASConstraintMaker *make) {
                make.width.mas_equalTo(0);
            }];
            break;
            
        case 1:
            _sexIV.image = [UIImage imageNamed:@"gender_icon_male"];
            break;
            
        default:
            _sexIV.image = [UIImage imageNamed:@"gender_icon_female"];
            break;
    }
//    _realNameIV.hidden = !([model.verified integerValue] == 1);
    if ([model.vip_status integerValue] == 1) {
        _vipIV.hidden = NO;
        
    } else {
        _vipIV.hidden = YES;

    }
    
}


-(void)removeAction{
    if (_btnClick) {
        _btnClick(self);
    }
}


@end
